/*
 *    Copyright (c) 2018-2025, nart All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: nart
 */

package com.nai365.nart.product.entity;


import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * sku信息
 *
 * @author baogs
 * @date 2022-07-01 11:05:45
 */
@Data
@TableName("pms_sku_info")
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "sku信息")
public class SkuInfo extends Model<SkuInfo> {

	private static final long serialVersionUID = 1L;

	/**
	 * skuId
	 */
	@TableId(type = IdType.ASSIGN_ID)
	@ApiModelProperty(value = "skuId")
	private Long skuId;

	/**
	 * spuId
	 */
	@ApiModelProperty(value = "spuId")
	private Long spuId;
	/**
	 * 拥有者id
	 */
	@ApiModelProperty(value = "拥有者id")
	private Long ownerId;

	/**
	 * 拥有者账户地址
	 */
	@ApiModelProperty(value = "拥有者账户地址")
	private String ownerAddress;

	/**
	 * 拥有者数量(每次流转+1)
	 */
	@ApiModelProperty(value = "拥有者数量(每次流转+1)")
	private Integer ownerCount;

	/**
	 * sku名称
	 */
	@ApiModelProperty(value = "sku名称")
	private String skuName;

	/**
	 * sku介绍描述
	 */
	@ApiModelProperty(value = "sku介绍描述")
	private String skuDesc;

	/**
	 * 所属分类id
	 */
	@ApiModelProperty(value = "所属分类id")
	private Long catalogId;

	/**
	 * 品牌id
	 */
	@ApiModelProperty(value = "品牌id")
	private Long brandId;
	/**
	 * 品牌名
	 */
	@ApiModelProperty(value = "品牌名")
	private String brandName;

	/**
	 * 默认图片
	 */
	@ApiModelProperty(value = "默认图片")
	private String skuDefaultImg;

	/**
	 * 标题
	 */
	@ApiModelProperty(value = "标题")
	private String skuTitle;

	/**
	 * 副标题
	 */
	@ApiModelProperty(value = "副标题")
	private String skuSubtitle;

	/**
	 * 价格
	 */
	@ApiModelProperty(value = "价格")
	private BigDecimal price;

	/**
	 * 销量
	 */
	@ApiModelProperty(value = "销量")
	private Long saleCount;

	/**
	 * 藏品编号
	 */
	@ApiModelProperty(value = "藏品编号")
	private String skuCode;

	/**
	 * DDC或BFT的token
	 */
	@ApiModelProperty(value = "DDC或BFT的token")
	private Long token;

	/**
	 * 交易id
	 */
	@ApiModelProperty(value = "交易id")
	private Long txId;

	/**
	 * 交易Hash
	 */
	@ApiModelProperty(value = "交易Hash")
	private String txHash;


	/**
	 * createTime
	 */
	@ApiModelProperty(value = "createTime")
	@TableField(fill = FieldFill.INSERT)
	private LocalDateTime createTime;

	/**
	 * updateTime
	 */
	@ApiModelProperty(value = "updateTime")
	@TableField(fill = FieldFill.INSERT_UPDATE)
	private LocalDateTime updateTime;

	/**
	 * 上架状态[0 - 新建，1 - 上架，2 - 下架]
	 */
	@ApiModelProperty(value = "状态[0 - 空闲，1 - 转售，2 - 质押，3-回收,4-合成,6-锁定]")
	private Integer publishStatus;

	/**
	 * 购买时间,一级购买成功更新,二级交易不更新
	 */
	@ApiModelProperty(value = "购买时间,一级购买成功更新,二级交易不更新")
	private LocalDateTime purchaseTime;

	/**
	 * 能否回收
	 *
	 * @return boolean
	 */
	@ApiModelProperty(value = "能否回收")
	public Boolean getAbleRecovery() {
		if (this.purchaseTime == null) {
			return false;
		}
		LocalDateTime now = LocalDateTime.now();
		LocalDateTime beginTime = purchaseTime.plusDays(1);
		LocalDateTime endTime = purchaseTime.plusDays(7);
		return now.isAfter(beginTime) && now.isBefore(endTime) && ownerCount <= 1 && publishStatus == 0;
	}

}
